package j2024.j202407;

import java.util.*;

public class j0715 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            char[] ss = s.toCharArray();
            Stack<Character> ret = new Stack<>();
            int len = ss.length;
            for (int i = 0; i < len; i++) {
                if(ret.isEmpty()){
                    ret.add(ss[i]);
                    continue;
                }
                if(!ret.isEmpty()){
                    char tmp = ret.peek();
                    if(tmp == ss[i]){
                        ret.pop();
                        continue;
                    }else {
                        ret.add(ss[i]);
                    }
                }
            }
            char[] retu = new char[ret.size()];
            int sz = ret.size();
            if(sz==0){
                System.out.println(0);
            }else {
                for (int i = 0; i < sz; i++) {
                    retu[i] = ret.pop();
                }
                for (int i = sz-1; i >= 0; i--) {
                    System.out.print(retu[i]);
                }
            }

        }
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int count = 0;
            for (int i = a; i <= b; i++) {
                int tmp = i;
                while(tmp>0){
                    if(tmp%10==2){
                        count++;
                    }
                    tmp/=10;
                }
            }
            System.out.println(count);
        }

    }
    public ArrayList<Integer> intersection (ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        // write code here
        ArrayList<Integer> ret = new ArrayList<>();
        HashSet<Integer> hashSet = new HashSet<>();
        for (int i = 0; i < nums1.size(); i++) {
            hashSet.add(nums1.get(i));
        }
        for (int i = 0; i < nums2.size(); i++) {
            if(hashSet.contains(nums2.get(i))){
                hashSet.remove(nums2.get(i));
                ret.add(nums2.get(i));
            }
        }
        return ret;
    }
    public int ladderLength(String beginWord, String endWord, List<String> wordList) {
        char[] str = new char[26];
        for (int i = 0; i < 26; i++) {
            str[i] = (char)('a'+i);
        }
        //是否转换过
        HashSet<String> vis = new HashSet<>();
        //wordList
        HashSet<String> set = new HashSet<>();
        for(String s:wordList){
            set.add(s);
        }
        if(beginWord.equals(endWord)){
            return 1;
        }
        if(!set.contains(endWord)){
            return 0;
        }
        Queue<String> q = new LinkedList<>();
        q.add(beginWord);
        vis.add(beginWord);
        int ret = 1;
        while(!q.isEmpty()){
            ret++;
            int sz = q.size();
            while(sz--!=0){
                String ss = q.poll();
                for (int i = 0; i < ss.length(); i++) {
                    char[] s = ss.toCharArray();
                    for (int j = 0; j < 26; j++) {
                        s[i] = str[j];
                        String tmp = new String(s);
                        if(set.contains(tmp) && !vis.contains(tmp)){
                            if(tmp.equals(endWord)){
                                return ret;
                            }
                            vis.add(tmp);
                            q.add(tmp);
                        }
                    }
                }
            }
        }
        return 0;
    }


    public int cutOffTree(List<List<Integer>> forest) {
        List<int[]> trees = new ArrayList<>();
        int m = forest.size(),n = forest.get(0).size();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(forest.get(i).get(j) > 1){
                    trees.add(new int[]{i,j});
                }
            }
        }
        Collections.sort(trees,(a,b)->{
            return forest.get(a[0]).get(a[1]) - forest.get(b[0]).get(b[1]);
        });
        int step = 0;
        int bx = 0,by = 0;
        for (int i = 0; i < trees.size(); i++) {
            int[] tmp = trees.get(i);
            int x = tmp[0],y = tmp[1];
           int ret = bfs(forest,bx,by,x,y);
           if(ret == -1){
               return -1;
           }
           step+=ret;
           bx = x;
           by = y;
        }
        return step;
    }
    int[] dx = {0,0,-1,1};
    int[] dy = {1,-1,0,0};
    public int bfs(List<List<Integer>> forest,int bx,int by,int x,int y){
        if(bx==x && by==y){
            return 0;
        }
        int ret = 0;
        int m = forest.size(),n = forest.get(0).size();
        Queue<int[]> q = new LinkedList<>();
        boolean[][] vis = new boolean[m][n];
        q.add(new int[]{bx,by});
        vis[bx][by] = true;
        while(!q.isEmpty()){
            ret++;
            int sz = q.size();
            while(sz--!=0){
                int[] tmp = q.poll();
                for (int i = 0; i < 4; i++) {
                    int ex = tmp[0]+dx[i];
                    int ey = tmp[1]+dy[i];
                    if(ex>=0 && ex<m && ey>=0 && ey<n && !vis[ex][ey] && forest.get(ex).get(ey)!=0){
                        if(ex==x && ey==y){
                            return ret;
                        }
                        q.add(new int[]{ex,ey});
                        vis[ex][ey] = true;
                    }
                }
            }
        }
        return -1;
    }
}
